/**
 * @author zhouheng
 * @date 2022年03月15日 18:28
 */

package com.atguigu.common.constant;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.util.StringUtils;

public class Main1 {

    public static List<String> list  = new ArrayList<String>();
    static  {
        list.add("A");
        list.add("S");
        list.add("D");
        list.add("W");
    }

    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);

        String str = "S87;S7;W56;S75;A8;S84;W23;W19;W40;D73;S87;A39;W97;W78;A53;D16;D15;A50;W41;S87;D47;W56;D56;A23;A91;S25;D61;D53;D58;W88;W58;S61;D69;W74;D89;A92;D39;D62;S78;W72;W73;W35;S76;W35;S36;W39;A4;";

        String[] split = str.split(";");

        int x = 0;
        int y = 0;
        for (int i = 0; i < split.length; i++){
            if (vertifyCode(split[i])) {
                String point = split[i];
                String move = point.substring(0, 1);
                String replace = point.replace(move, "");
                switch (move) {
                    case "A":
                        x -=  Integer.parseInt(replace);
                        break;
                    case "D": {
                        x +=  Integer.parseInt(replace);
                        break;
                    }
                    case "W": {
                        y +=  Integer.parseInt(replace);
                        break;
                    }
                    case "S": {
                        y -=  Integer.parseInt(replace);
                        break;
                    }
                }
            }
        }

        System.out.println("(" + x +","+y+")");
    }

    private static boolean vertifyCode(String s) {
        if (StringUtils.isEmpty(s) || s.length() != 3) {
            return false;
        }

        if (!list.contains(s.substring(0,1))) {
            return false;
        }

        String substring = s.substring(1, s.length() - 1);

        for (int i = 0; i < substring.length(); i++) {
            boolean digit = Character.isDigit(substring.charAt(i));

            if (!digit) {
                return false;
            }
        }

        return true;
    }
}
